package com.readytheory.thisisstupid;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class BlowoutBumper {
    private static final String PERSISTENCE_UNIT_NAME = "Blowout";
    private static EntityManagerFactory factory;
    
    public int addOne() {
	factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
	EntityManager em = factory.createEntityManager();

	// Create new blowout
	em.getTransaction().begin();
	Blowout blowout = new Blowout();
	blowout.setSummary("This is a test");
	blowout.setDescription("This is a test");
	em.persist(blowout);
	em.getTransaction().commit();

	// Read the existing entries and write to console
	Query q = em.createQuery("select t from Blowout t");
	List<Blowout> todoList = q.getResultList();
	em.close();
	return todoList.size();
    }
}
